keyMap = {
    "globalSize": "Global mesh size",
    "damageCount": "Number of damage",
    "damageType": "Type of damage",
    "damageCenterX": "Location of damage center x",
    "damageCenterY": "Location of damage center y",
    "damageCenterZ": "Location of damage center z",
    "honeycombCoreHeight": "Height of honeycomb core",
    "damageExcisionDiameter": "Diameter of damage excavation",
    "submodelSizeL": "Submodel length",
    "submodelSizeW": "Submodel width",
    "搭接宽度": "Overlap width",
    "adhesiveLayerThickness": "Thickness of adhesive layer",
    "presetModelPath": "Simulation Model Path",
    "additionalExcisionSize": "额外挖除尺寸",
    "lowerAdhesiveLayersCount": "下铺层修补胶层层数",
    "topPlyNumber": "Number of layers in upper skin",
    "topRepairPlyNumber": "Number of layers of upper skin patching",
    "bottomRepairPlyNumber": "下铺层修补层层数",
    "bottomPlyNumber": "Number of layers in lower skin",
    "topPlyTable": "Upper skin",
    "bottomPlyTable": "Lower skin",
    "topRepairPlyTable": "Upper skin patching",
    "bottomRepairPlyTable": "Lower skin patching optim",
    "honeycombCore": "Honeycomb core material",
    "bottomFillPlyTable": "Fill layer in the lower skin",
    "loadCondition": "Load",
    "loadAmplitude": "Amplitude of load",
    "厚度": "Thickness",
    "材料名称": "Name of material",
    "Angle": "Layer angle",
    "铺层名称": "No. of pavement",
    "method": "Optimization function",
    "algorithm": "Optimization algorithm",
    "goal": "Optimization objective",
    "constraints": "Constraint",
    "lapWidthTable": "Overlap width optim",
    "topAngleTable": "Upper skin patching optim",
    "replaceCoreTable": "Replacement core",
    "material": "材料",
    "presetModelPath": "预设模型路径",
    "shapeParameter": "形状参数",
    "specimenCoefficient": "试件系数",
    "confidenceCoefficient": "置信系数",
    "reliabilityCoefficient": "可靠性系数",
    "lifeAnalysisResults": "寿命统计结果",
    "statisticsTable": "寿命统计情况",
}

valueMap = {
    "Global mesh size": "globalSize",
    "Number of damage": "damageCount",
    "Type of damage": "damageType",
    "Location of damage center x": "damageCenterX",
    "Location of damage center y": "damageCenterY",
    "Location of damage center z": "damageCenterZ",
    "Height of honeycomb core": "honeycombCoreHeight",
    "Diameter of damage excavation": "damageExcisionDiameter",
    "Submodel length": "submodelSizeL",
    "Submodel width": "submodelSizeW",
    "Overlap width": "搭接宽度",
    "Thickness of adhesive layer": "adhesiveLayerThickness",
    "Simulation Model Path": "presetModelPath",
    "额外挖除尺寸": "additionalExcisionSize",
    "下铺层修补胶层层数": "lowerAdhesiveLayersCount",
    "Number of layers in upper skin": "topPlyNumber",
    "Number of layers of upper skin patching": "topRepairPlyNumber",
    "下铺层修补层层数": "bottomRepairPlyNumber",
    "Number of layers in lower skin": "bottomPlyNumber",
    "Upper skin": "topPlyTable",
    "Lower skin": "bottomPlyTable",
    "Upper skin patching": "topRepairPlyTable",
    "Lower skin patching optim": "bottomRepairPlyTable",
    "Honeycomb core material": "honeycombCore",
    "Fill layer in the lower skin": "bottomFillPlyTable",
    "Load": "loadCondition",
    "Amplitude of load": "loadAmplitude",
    "Thickness": "厚度",
    "Name of material": "材料名称",
    "Layer angle": "Angle",
    "No. of pavement": "铺层名称",
    "Optimization function": "method",
    "Optimization algorithm": "algorithm",
    "Optimization objective": "goal",
    "Constraint": "constraints",
    "Overlap width optim": "lapWidthTable",
    "Upper skin patching optim": "topAngleTable",
    "Replacement core": "replaceCoreTable",
    "材料": "material",
    # "材料":"Type of material",
    "预设模型路径": "presetModelPath",
    "形状参数": "shapeParameter",
    "试件系数": "specimenCoefficient",
    "置信系数": "confidenceCoefficient",
    "可靠性系数": "reliabilityCoefficient",
    "寿命统计结果": "lifeAnalysisResults",
    "寿命统计情况": "statisticsTable",
}


def convertKey(data, type, isNoList=False):
    res = {}
    if type == 0:
        for key, values in data.items():
            # if valueMap.get(key):
            #     res[valueMap.get(key) or ""] = values
            # else:
            # res[key] = values
            res[valueMap.get(key) or ""] = values
            if isinstance(values, list) and not isNoList:
                newValues = []
                for item in values:
                    subDict = {}
                    for k, v in item.items():
                        subDict[valueMap.get(k) or ""] = v
                    newValues.append(subDict)
                res[valueMap.get(key) or ""] = newValues
    elif type == 1:
        for key, values in data.items():
            res[keyMap.get(key) or ""] = values
            if isinstance(values, list) and not isNoList:
                newValues = []
                for item in values:
                    subDict = {}
                    for k, v in item.items():
                        subDict[keyMap.get(k) or ""] = v
                    newValues.append(subDict)
                res[keyMap.get(key) or ""] = newValues
    return res
